package com.unohacha.qqj.fzdr.main;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.adapter.BaseRVAdapter;
import com.unohacha.qqj.fzdr.adapter.BaseViewHolder;
import com.unohacha.qqj.fzdr.bean.homebean.HomeAppExpressBean;
import com.unohacha.qqj.fzdr.imp.MyCallBack;
import com.unohacha.qqj.fzdr.imp.UrlConfig;
import com.unohacha.qqj.fzdr.imp.XUtil;
import com.unohacha.qqj.fzdr.util.Prefer;
import com.unohacha.qqj.mylibrary.base.BaseActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 快递查询详情
 */
public class ExpressCheckActivity extends BaseActivity {

    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;
    @BindView(R.id.express_logo)
    ImageView expressLogo;
    @BindView(R.id.express_type)
    TextView expressType;
    @BindView(R.id.express_name)
    TextView expressName;
    @BindView(R.id.car_list_recycler)
    RecyclerView carListRecycler;

    private HomeAppExpressBean.DataBeanX mExpressData;
    private BaseRVAdapter mBaseAdapter;
    private List<HomeAppExpressBean.DataBeanX.DataBean> mList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_express_check;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setText("快递查询");
        commonRightImage.setVisibility(View.GONE);
        commonRightText.setVisibility(View.GONE);
        carListRecycler.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        if (null != getIntent()){
            mExpressData = (HomeAppExpressBean.DataBeanX) getIntent().getSerializableExtra("data");
            mList.addAll(mExpressData.getData());
            Glide.with(this).load(mExpressData.getLogo()).into(expressLogo);
            expressName.setText(mExpressData.getName() + ":" + mExpressData.getExpress_no());
            expressType.setText(mExpressData.getName());
            setBaseAdapter();
        }
       
    }

    @OnClick(R.id.common_back)
    public void setCommonBack(){
        finish();
    }
    
    //设置数据
    private void setBaseAdapter(){
        mBaseAdapter = new BaseRVAdapter(this,mExpressData.getData()) {
            
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_express_item;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                View view_ver = holder.getView(R.id.view_ver);
                TextView express_time = holder.getTextView(R.id.express_time);
                TextView express_time_one = holder.getTextView(R.id.express_time_one);
                TextView express_content = holder.getTextView(R.id.express_content);

               String time =  mExpressData.getData().get(position).getTime();
                express_time_one.setText(time.substring(0,time.indexOf(" ")));
                express_time.setText(time.substring(time.indexOf(" "),time.length()));
                express_content.setText(mExpressData.getData().get(position).getContext());
                
                if (position == 0){
                    express_time.setTextColor(getResources().getColor(R.color.green1ccf70));
                    express_time_one.setTextColor(getResources().getColor(R.color.green1ccf70));
                    express_content.setTextColor(getResources().getColor(R.color.green1ccf70));
                    view_ver.setVisibility(View.GONE);
                }else {
                    express_time.setTextColor(getResources().getColor(R.color.text_black_666));
                    express_time_one.setTextColor(getResources().getColor(R.color.text_black_666));
                    express_content.setTextColor(getResources().getColor(R.color.text_black_666));
                    view_ver.setVisibility(View.VISIBLE);
                }
            }

        };
        carListRecycler.setAdapter(mBaseAdapter);
        mBaseAdapter.notifyDataSetChanged();
    }
    
   
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
